<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<input type="button" value="添加" onclick="gotoAdd()">  
<table class="table">
  <tr>
    <th>id</th>
    <th>名称</th>
    <th>url地址</th>
    <th>创建时间</th>
    <th>操作</th>
    
  </tr>
  <c:forEach items="${pageLink.list}" var="link">
	  <tr>
	    <td>${link.id}</td>
	    <td>${link.name}</td>
	    <td>${link.url}</td>
	    <td><fmt:formatDate value="${link.created}" pattern="yyyy-MM-dd"/> </td>
	    <td>
	        <input type="button" onclick="delLink(${link.id})" value="删除"> 
	       <input type="button" onclick="updateLink(${link.id})" value="修改">
	    </td>
	  </tr>
  </c:forEach>
  
  <!-- 分页 -->
  <tr>
   <td colspan="5">
   		<nav aria-label="...">
		  <ul class="pagination">
		    
		    <li class="page-item">
		      <a class="page-link" href="javascript:showLink(1)" >首页</a>
		    </li>
		    <c:forEach begin="1" end="${pageLink.pages}" var="page">
		    	<li class="page-item"><a class="page-link" href="javascript:showLink(${page})">${page}</a></li>
		    </c:forEach>
		    <li class="page-item">
		      <a class="page-link" href="javascript:showLink(${pageLink.pages})">尾页</a>
		    </li>
		  </ul>
		</nav>
   </td>
   </tr>
</table>
<script type="text/javascript">
<!--

//-->
// 分页
 function showLink(page){
		$("#workContent").load("/admin/linklist?page="+page)
 }
 // 跳转到添加的页面
 function gotoAdd(){
	 $("#workContent").load("/admin/addlink")
 }
 
 function delLink(id){
	 //删除
	 $.post("/admin/delLink",{id:id},
			 function(data){
		 // 删除后刷新页面
		 $("#workContent").load("/admin/linklist?page=${pageLink.pageNum}")
			 
	 	}
	 )
 }
 
 function updateLink(id){
	 $("#workContent").load("/admin/toUodatelink?id="+id)
 }
</script>

    
